home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Browsers, Managers & Extensions
/
Firefox Backup Extension 6.0.3
/
chrome
/
febe.jar
/
content
/
febeOptions.js
< prev
next >
Wrap
Text File
|
2008-08-11
|
15KB
|
411 lines
// author: Chuck Baker
// contact: febe@customsoftwareconsult.com
// Version 6.0
window.addEventListener("load",febeBuProfileCheck,true);
function febeBuSelectAll(bool) {
var box = document.getElementById("buItems");
var checkboxes = box.getElementsByTagName("checkbox");
for(i=0; i<checkboxes.length; i++){
if(!checkboxes[i].disabled){
checkboxes[i].setAttribute("checked",bool);
var id = checkboxes[i].id; // The ID is the same as the preference name. Clever, eh?
var prefname = id.replace(/_/g,".");
febePrefs.setBoolPref(prefname,bool);
}//if
}//for
febeBuProfileCheck();
return true;
}//febeBuSelectAll()
function febeBuProfileCheck(){
febeSetMsgs();
try{
var buType = febePrefs.getCharPref("extensions.febe.buType");
if(buType == "profile"){ // Disable options if profile backup is checked
document.getElementById("buExtensions_id").setAttribute("disabled",true);
document.getElementById("buThemes_id").setAttribute("disabled",true);
document.getElementById("additionalItemsID").setAttribute("disabled",true);
} else {
document.getElementById("buExtensions_id").setAttribute("disabled",false);
document.getElementById("buThemes_id").setAttribute("disabled",false);
document.getElementById("additionalItemsID").setAttribute("disabled",false);
febeOptionsCheck();
}//if
}catch(e){;}
window.removeEventListener("load",febeBuProfileCheck,true);
return true;
}//febeBuProfileCheck()
function febeSelExt(){
// Select extensions to backup
var w = "chrome://febe/content/febeSelExt.xul";
window.open(w, "FEBE Select Extensions", "chrome,alwaysRaised,centerscreen,resizable");
}//febeSelExt()
function febeSelTheme(){
// Select extensions to backup
var w = "chrome://febe/content/febeSelTheme.xul";
window.open(w, "FEBE Select Themes", "chrome,alwaysRaised,centerscreen,resizable");
}//febeSelTheme()
function febeSelBUDestDir(){
// Select backup destinaton directory
const nsIFilePicker = Ci.nsIFilePicker;
var fp = Cc["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
fp.init(window, febeMsg[5], nsIFilePicker.modeGetFolder);
fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
// Set default directory to current backup directory
if(febePrefs.prefHasUserValue("extensions.febe.extBUdir")){
extBUdir = febeGetUnicharPref("extensions.febe.extBUdir");
if(extBUdir != ""){
var dd = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
dd.initWithPath(extBUdir);
fp.displayDirectory = dd;
}//if
}//if
var rv = fp.show();
if (rv == nsIFilePicker.returnOK){
rv = fp.file;
extBUdir = rv.path;
febeSetUnicharPref("extensions.febe.extBUdir", extBUdir);
document.getElementById("DestDirID").value = extBUdir;
var d = document.getElementById("DestDirID");
d.setAttribute("value",extBUdir);
}//if
febeCheckBuDestDir();
return true;
}//febeSelBUDestDir()
function febeClearPrefs(){
var tmp = febeMsg[126]+"\n"+febeMsg[127]+"\n\n";
var style = "<style>color: red; font-weight: bold; font-size: 20px;</style>";
tmp += style+febeMsg[183]+"\n\n";
tmp += febeMsg[128]
var ok = febeConfirm(tmp);
if(!ok){return false;}
try {
var prefCount = {value:0};
var prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService);
var prefBranch = prefService.getBranch(null);
var prefArray = prefBranch.getChildList("extensions.febe." , prefCount);
var nsIPrefBranch = Ci.nsIPrefBranch;
for (i = 0; i < prefCount.value; i++){
if(prefBranch.prefHasUserValue(prefArray[i])){prefBranch.clearUserPref(prefArray[i]);}
}
prefBranch.deleteBranch("extensions.febe.");
// delete the destination file if it exists
var febeDataFile = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile);
febeDataFile.append(FEBEDATAFILE);
if(febeDataFile.exists()){febeDataFile.remove(false);}
}catch (e) {
febeAlert(e);
return false;
}
var version = getFebeVersion();
var prefName = "extensions.febe.previousversion";
febePrefs.setCharPref(prefName,version);
febeAlert(febeMsg[129]);
febeRestartFx();
return true;
}//febeClearPrefs()
function febeViewBuDir(){
var febeBuDestDir = document.getElementById("DestDirID").value;
febeOpenLink("file:///"+febeBuDestDir);
return true;
}//febeViewBuDir()
function febeViewInstallDir(){
var febeInstallDir = document.getElementById("febeInstallPath").value;
febeOpenLink("file:///"+febeInstallDir);
return true;
}//febeViewInstallDir()
function febeCheckBuDestDir(){
if(document.getElementById("DestDirID") && document.getElementById("DestDirID").value != ""){
document.getElementById("febeviewbudirbtnID").disabled = false;
}else{
document.getElementById("febeviewbudirbtnID").disabled = true;
}//if
return true;
}//febeCheckBuDestDir()
function febeDisableOpts(){
try{ // Use a try blocks because statements refer to different preference windows which may not be loaded
document.getElementById("clearwarn_id").disabled = !document.getElementById("clearDestDir_id").checked;
}catch(e){;}
try{
document.getElementById("maxBuDirsLabelID").disabled = !document.getElementById("useTimestampedDir_id").checked;
}catch(e){;}
try{
document.getElementById("maxBuDirsID").disabled = !document.getElementById("useTimestampedDir_id").checked;
}catch(e){;}
try{
document.getElementById("febeTimestampFormatLabelID").disabled = !document.getElementById("useTimestampedDir_id").checked;
}catch(e){;}
try{
document.getElementById("febeTimestampFormat1ID").disabled = !document.getElementById("useTimestampedDir_id").checked;
}catch(e){;}
try{
document.getElementById("febeTimestampFormat2ID").disabled = !document.getElementById("useTimestampedDir_id").checked;
}catch(e){;}
try{
document.getElementById("febeclearbuinprogresstbtn").disabled = !febeBuInProgress();
}catch(e){;}
febePlatform = febeGetPlatform();
return true;
}//febeDisableOpts()
function febeCloseButtonEtc(){
febeGetPlatform();
try{ // Use a try block because statements refer to different preference windows which may not be loaded
// Show close button for Mac OS X users because they don't get buttons for <prefwindow>
// Looks like Fx3 doesn't show for *nix either
if(febePlatform == 2 || febePlatform == 3){
document.getElementById("febeMacAcceptBtn").hidden = false;
}//if
// Set text direction
var textdir = document.getElementById("febeTextDir").value;
if(!textdir){textdir = "ltr";}
var prefName = "extensions.febe.orientation";
febePrefs.setCharPref(prefName,textdir);
// Add event listeners
var d = document.getElementById("febeTimestampFormatID");
d.addEventListener("RadioStateChange", febeTimestampDirCheck, false);
}catch(e){;}
return true;
}//febeCloseButtonEtc()
function febeOptionsCheck(){
// Enable/disable options
// Create pointer to profile directory
febeProfDir = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile);
var buType = febePrefs.getCharPref("extensions.febe.buType");
if(buType == "profile"){return true;}
var tmp = "";
// Check userChrome.css
var d = document.getElementById("extensions_febe_buUserChrome");
var profileDir = febeProfDir.clone();
profileDir.append("chrome");
profileDir.append("userChrome.css");
if(!profileDir.exists()){
if(d.checked == true){tmp += d.label + "\n";}
d.checked = false;
d.setAttribute("disabled",true);
var prefName = "extensions.febe.buUserChrome";
febePrefs.setBoolPref(prefName,false);
}else{
d.setAttribute("disabled",false);
}//if
// Check cookies.txt
var d = document.getElementById("extensions_febe_buCookies");
var profileDir = febeProfDir.clone();
profileDir.append("cookies.sqlite");
if(!profileDir.exists()){
if(d.checked == true){tmp += d.label + "\n";}
d.checked = false;
d.setAttribute("disabled",true);
var prefName = "extensions.febe.buCookies";
febePrefs.setBoolPref(prefName,false);
}else{
d.setAttribute("disabled",false);
}//if
// Check usernames/passwords
var d = document.getElementById("extensions_febe_buUserPwd");
var loginManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
var logins = loginManager.getAllLogins({});
if(logins.length < 1){
if(d.checked == true){tmp += d.label + "\n";}
d.checked = false;
d.setAttribute("disabled",true);
var prefName = "extensions.febe.buUserPwd";
febePrefs.setBoolPref(prefName,false);
}else{
d.setAttribute("disabled",false);
}//if
// Check searchPlugins
var d = document.getElementById("extensions_febe_buSearchPlugins");
var profileDir = febeProfDir.clone();
profileDir.append("searchplugins");
if(!profileDir.exists()){
if(d.checked == true){tmp += d.label + "\n";}
d.checked = false;
d.setAttribute("disabled",true);
var prefName = "extensions.febe.buSearchPlugins";
febePrefs.setBoolPref(prefName,false);
}else{
d.setAttribute("disabled",false);
}//if
// Check history.dat
var d = document.getElementById("extensions_febe_buBrowserHistory");
var historyService = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
if(!historyService.hasHistoryEntries){
if(d.checked == true){tmp += d.label + "\n";}
d.checked = false;
d.setAttribute("disabled",true);
var prefName = "extensions.febe.buBrowserHistory";
febePrefs.setBoolPref(prefName,false);
}else{
d.setAttribute("disabled",false);
}//if
// Check formhistory.dat
var d = document.getElementById("extensions_febe_buFormFillHistory");
var dbFile = febeProfDir.clone();
dbFile.append("formhistory.sqlite");
var storageService = Cc["@mozilla.org/storage/service;1"].getService(Ci.mozIStorageService);
var db = storageService.openDatabase(dbFile);
var sQuery = "SELECT * FROM moz_formhistory";
var stmt = db.createStatement(sQuery);
if(!stmt.executeStep()){
if(d.checked == true){tmp += d.label + "\n";}
d.checked = false;
d.setAttribute("disabled",true);
var prefName = "extensions.febe.buFormFillHistory";
febePrefs.setBoolPref(prefName,false);
}else{
d.setAttribute("disabled",false);
}//if
// Check permissions
var d = document.getElementById("extensions_febe_buPermissions");
var dbFile = febeProfDir.clone();
dbFile.append("permissions.sqlite");
var storageService = Cc["@mozilla.org/storage/service;1"].getService(Ci.mozIStorageService);
var db = storageService.openDatabase(dbFile);
var sQuery = "SELECT * FROM moz_hosts";
var stmt = db.createStatement(sQuery);
if(!stmt.executeStep()){
if(d.checked == true){tmp += d.label + "\n";}
d.checked = false;
d.setAttribute("disabled",true);
var prefName = "extensions.febe.buPermissions";
febePrefs.setBoolPref(prefName,false);
}else{
d.setAttribute("disabled",false);
}//if
// Check user-defined backups
var d = document.getElementById("extensions_febe_buUDBu");
if(febeUDBuInit() == false){
if(d.checked == true){tmp += d.label + "\n";}
d.checked = false;
d.setAttribute("disabled",true);
var prefName = "extensions.febe.buUDBu";
febePrefs.setBoolPref(prefName,false);
}else{
d.setAttribute("disabled",false);
}//if
// Display message
if(febex == true){return;} // Display msg only once
febex = true;
if(tmp.length != 0){
var style = "<style>color: red; font-weight: bold; font-size: 15px;</style>";
tmp = style+febeMsg[184]+"\n\n"+tmp;
febeAlert(tmp);
}//if
}//febeOptionsCheck()
function febeProfileWizard(){
var wizard = "chrome://mozapps/content/profile/createProfileWizard.xul";
window.open(wizard, "FEBE Help", "chrome,alwaysRaised,centerscreen,resizable");
}//febeProfileWizard()
function febeTimestampDirCheck(event){
var selected = document.getElementById("febeTimestampFormatID").selectedItem.value;
var current = febePrefs.getCharPref("extensions.febe.timestamp.format");
if(current == selected){return true;}
if(!febeGetBDD()){return false;} // Get backup destination directory
var tags = ["ISO8601","European"];
var masks = [/^FEBE \d\d\d\d \d\d\.\d\d \d\d\.\d\d\.\d\d$/,/^FEBE \d\d\d\d \d\d-\d\d \d\d\.\d\d\.\d\d$/];
var which = document.getElementById("febeTimestampFormatID").selectedIndex;
var mask = masks[which];
var dirArray = {};
var numDirsToRename = 0;
var buDirRoot = febeBuDesDir.clone();
var entries = buDirRoot.directoryEntries;
// Count the number of directories that need to be renamed
while(entries.hasMoreElements()){
var entry = entries.getNext();
entry.QueryInterface(Ci.nsIFile);
var dirName = entry.leafName;
if(!entry.isDirectory()){continue;}
if(!dirName.match(mask)){continue;}
numDirsToRename++;
dirArray[dirName] = febeNewDirName(which,dirName);
}//while
if(numDirsToRename == 0){return true;}
var newformat,oldformat;
switch(which){
case 0:
oldformat = tags[1];
newformat = tags[0];
break;
case 1:
oldformat = tags[0];
newformat = tags[1];
break;
}//switch
var tmp = febeMsg[204].replace("%NUMDIR%",numDirsToRename);
tmp = tmp.replace("%FORMT%",oldformat)+"\n";
tmp += febeMsg[205].replace("%NEWFORMAT%",newformat)+"\n\n"+febeMsg[41];
tmp="<style>color: red; font-weight: bold; font-size: 20px;</style>"+tmp;
if(!febeConfirm(tmp)){
switch(which){ // Switch it back to where it was
case 0:
document.getElementById("febeTimestampFormatID").selectedIndex = 1;
break;
case 1:
document.getElementById("febeTimestampFormatID").selectedIndex = 0;
break;
}//switch
febePrefs.setCharPref("extensions.febe.timestamp.format",current);
febeAlert(febeMsg[206]);
return false;
}//if
// Rename the directories
for(var i in dirArray){
var rnDir = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
rnDir.initWithPath(buDirRoot.path);
rnDir.append(i);
var filespec = Cc["@mozilla.org/filespec;1"].createInstance(Ci.nsIFileSpec);
filespec.nativePath = rnDir.path;
filespec.rename(dirArray[i]);
//alert("Rename "+i+" to "+dirArray[i])
}//for
tmp = febeMsg[207].replace("%NUMDIR%",numDirsToRename);
tmp = tmp.replace("%NEWFORMAT%",newformat);
febeAlert(tmp);
febePrefs.setCharPref("extensions.febe.timestamp.format",selected)
}//febeTimestampDirCheck()
function febeClearBuInProgressFlag(){
febePrefs.setBoolPref("extensions.febe.backupInProgress",false);
document.getElementById("febeclearbuinprogresstbtn").disabled = true;
}//febeClearBuInProgressFlag()
//alert("febeOptions.js loaded");